<template>
  <div style="width: 100%;height: 100%">
    <el-dialog title="编辑学生" :visible.sync="dialogFormVisible">
      <el-form :model="editForm">
        <el-form-item size="mini"  label="学生姓名" >
          <el-input size="mini" v-model="editForm.studentName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item size="mini" label="身份证号" >
          <el-input size="mini" v-model="editForm.idCard" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item size="mini" label="性别" >
          <el-input size="mini" v-model="editForm.sex" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item size="mini" label="联系方式" >
          <el-input size="mini" v-model="editForm.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item size="mini" label="登陆密码" >
          <el-input size="mini" v-model="editForm.password" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="editSubmit()">确 定</el-button>
      </div>
    </el-dialog>
    <el-table
        height="100%"
        v-loading="loading"
        element-loading-text="拼命加载中"
        :data="tableData"
        style="width: 100%;"
    >
    <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
          <el-form-item label="学生ID">
            <span>{{ props.row.sid}}</span>
          </el-form-item>
          <el-form-item label="身份证号码">
            <span>{{ props.row.idCard}}</span>
          </el-form-item>
          <el-form-item label="地址">
            <span>{{ props.row.address}}</span>
          </el-form-item>
          <el-form-item label="联系方式">
            <span>{{ props.row.phone}}</span>
          </el-form-item>
          <el-form-item label="毕业学校">
            <span>{{ props.row.uid}}</span>
          </el-form-item>

        </el-form>
      </template>
    </el-table-column>
    <el-table-column label="姓名" prop="studentName"></el-table-column>
    <el-table-column label="性别" prop="sex"></el-table-column>
    <el-table-column label="年级" prop="yearNum"></el-table-column>
    <el-table-column align="right">
      <template slot="header">
        <input
            class="seach"
            @keyup.enter="searchHandle()"
            v-model="search"
            size="mini"
            placeholder="输入关键字搜索"
        />
      </template>
      <template slot-scope="scope">
        <el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">Edit</el-button>
        <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">Delete</el-button>
      </template>
    </el-table-column>
    </el-table>
    <div style="float: right;margin-right: 10px" class="block">
      <el-pagination
          background
          hide-on-single-page
          @current-change="currentChange"
          layout="prev, pager, next"
          :current-page="page.current"
          :total="page.total"></el-pagination>
    </div>
  </div>
</template>

<script>
import {getStudent,upStudent,delStudent} from "../../../network/admin"
export default {
  name: "stuList",
  data() {
    return {
      dialogFormVisible:false,
      editForm:{
        sid:'',
        universityName:'',
        password:''
      },
      tableData:'',
      search: "",
      loading:false,
      page: {
        //后端传过来的数据,包含total(总条目),pages(总页数),records(数据),current(当前页号)
      }
    };
  },
  created() {
    this.getData()
  },
  methods:{
    getData(){
      getStudent(localStorage.getItem('userId'))
      .then(res=>{
        this.tableData=res.data.extend.list
        console.log(res)
      })
    },
    handleDelete(index,row){
      delStudent(row.sid)
      .then(res=>{
        console.log(res)
        this.$message.success("删除成功!")
        this.getData()
      })
    },
    handleEdit(){
      this.dialogFormVisible=true
    }
  }
}
</script>

<style scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>